package gold.digger;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC519 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        private int row, col, n;
        private HashMap<Integer, Integer> posMap;
        private Random random;

        public Solution(int n_rows, int n_cols) {
            row = n_rows;
            col = n_cols;
            n = row * col;
            posMap = new HashMap<>();
            random = new Random();
        }

        public int[] flip() {
            if (n < 0) return null;
            //随机选择一个下标
            int r = random.nextInt(n--);
            int x = posMap.getOrDefault(r, r); // 查看是否存在交换关系
            // 原下标与尾部下标交换（使用map记录origin->tail交换关系）
            posMap.put(r, posMap.getOrDefault(n, n));
            return new int[]{x / col, x % col};
        }

        public void reset() {
            posMap = new HashMap<>();
            n = row * col;
        }

    }

    public void run() {
        Solution solution = new Solution(3, 3);
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC519 an = new LC519();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
